package it.unisalento.appsalento.adapter;

import it.unisalento.R;

import java.util.HashMap;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

@Deprecated
public class EsamiAdapter extends BaseAdapter {
	public static final String KEY_CODICE_ESAME = "codiceEsame";
	public static final String KEY_NOME_ESAME = "nomeEsame";
	public static final String KEY_IMAGE_APP = "statoApprovaizone";
	public static final String KEY_IMAGE_STATO = "statoEsame";
	
	LayoutInflater inflater;
	//ImageView list_image;
	List<HashMap<String, String>> contentDataCollection;
	ViewHolder holder;
	@Override
	public int getCount() {
		return  contentDataCollection.size();
	}

	public EsamiAdapter(Activity act, List<HashMap<String, String>> map) {
	    this.contentDataCollection = map;
	    inflater = (LayoutInflater) act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public EsamiAdapter(LayoutInflater i, List<HashMap<String, String>> map) {
	    this.contentDataCollection = map;
	    inflater = i;
	}
	
	@Override
	public Object getItem(int position) {
		return this.contentDataCollection.get(position);
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
	    if (convertView == null) {

	    	view = inflater.inflate(R.layout.row_libretto, null);
	        holder = new ViewHolder();
	        holder.nomeEsame = (TextView) view.findViewById(R.id.nomeEsame);
	        holder.codiceEsame = (TextView) view.findViewById(R.id.codiceEsame);
	        holder.statoEsame = (ImageView) view.findViewById(R.id.statoEsame);
	        //holder.statoApprovaizone = (ImageButton) view.findViewById(R.id.statoApprovaizone);
	        view.setTag(holder);
	    } else {
	        holder = (ViewHolder) view.getTag();
	    }
	    if(contentDataCollection.get(position).get(KEY_IMAGE_STATO) != null && 
	    		!"".equals(contentDataCollection.get(position).get(KEY_IMAGE_STATO))){
		    String drawableStatoName = contentDataCollection.get(position).get(KEY_IMAGE_STATO); 
		    int imageStotoResource = view.getContext().getResources().getIdentifier(drawableStatoName, "drawable", view.getContext().getPackageName());
	
		    Drawable imageStato = view.getContext().getResources().getDrawable(imageStotoResource);
		  
		    holder.statoEsame.setImageDrawable(imageStato);
	    }
	    if(contentDataCollection.get(position).get(KEY_IMAGE_APP) != null && 
	    		!"".equals(contentDataCollection.get(position).get(KEY_IMAGE_APP))){
		    String drawableApprovName = contentDataCollection.get(position).get(KEY_IMAGE_APP); 
		    int imageAppResource = view.getContext().getResources().getIdentifier(drawableApprovName, "drawable", view.getContext().getPackageName());
	
		    Drawable imageApp = view.getContext().getResources().getDrawable(imageAppResource);
		  
		    //holder.statoApprovaizone.setImageDrawable(imageApp);
	    }
	    holder.nomeEsame.setText(contentDataCollection.get(position).get(KEY_NOME_ESAME));
	    holder.codiceEsame.setText(contentDataCollection.get(position).get(KEY_CODICE_ESAME));
	    
	    
	    return view;
	}
	
	/*
	 * 
	 * */
	static class ViewHolder {
		ImageView statoEsame;
	    TextView nomeEsame;
	    TextView codiceEsame;
	    ImageButton statoApprovaizone;
	}
	

}
